package com.yinhai.adapter;

import java.util.List;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.androidquery.AQuery;
import com.yinhai.activity.CloudNoteActivity;
import com.yinhai.activity.R;
import com.yinhai.model.CloudNote;

public class CloudNoteAdapter extends BaseAdapter {
	//private Context ctx;
	private List<CloudNote> list;
	private LayoutInflater inflater;
	CloudNoteActivity context;
	CloudNote selectCn;
    private AQuery aq = null;
	public CloudNoteAdapter(CloudNoteActivity context, List<CloudNote> list) {
		this.context = context;
		this.list = list;
		this.inflater = LayoutInflater.from(context);
	}
	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.sortcloudnote_list_item, null);
			holder = new ViewHolder();
			holder.title = (TextView) convertView.findViewById(R.id.title);
			holder.icon = (ImageView) convertView.findViewById(R.id.icon);
			holder.del = (ImageView) convertView.findViewById(R.id.del);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.title.setText(list.get(position).getNote());
		aq = new AQuery(convertView);
		selectCn = list.get(position);
		
		
		aq.id(R.id.del).tag(selectCn).clicked(context.DelItme);
		
		/*holder.del.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) { }
		});*/
		return convertView;
	}

	public static class ViewHolder {
		TextView title;
		ImageView icon;
		ImageView del;
	}

}
